#import "AllSongsViewController.h"
#import "SongsCustomCell.h"

@interface AllSongsViewController ()
@property (weak, nonatomic) IBOutlet UITableView *allSongsTableView;
@property SongsSingleton* songSingleton ;
@end

@implementation AllSongsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.allSongsTableView registerNib:[UINib nibWithNibName:@"SongsCustomCell" bundle:nil]forCellReuseIdentifier:@"Songs"];
    self.allSongsTableView.dataSource = self;
    self.allSongsTableView.delegate = self;
    [self.allSongsTableView setOpaque:NO];
    [self.allSongsTableView setBackgroundColor:[UIColor clearColor]];
    self.songSingleton=[[SongsSingleton alloc]init];
    //[self.songSingleton deleteCoreData];
    //[self.songSingleton fillCoreData];
    
    [self.songSingleton fetchData];

}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
   // [[NSNotificationCenter defaultCenter] postNotificationName:@"kKYNArcTabToggleTabBar" object:nil];
}

#pragma mark TableView config

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* cellId = @"Songs";
    SongsCustomCell *cell = [self.allSongsTableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    cell.favouritesButton.tag=indexPath.row;
    cell.songNameLabel.text=[self.songSingleton songForIndex:indexPath.row ].songName;
    cell.artistNameLabel.text=[self.songSingleton songForIndex:indexPath.row ].author ;
    return cell;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.songSingleton numberOfNotesInAllSongs];;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 103;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SongViewController* SVC=[[SongViewController alloc]initWithNibName:@"SongViewController" bundle:nil];
    SVC.currentSong=[self.songSingleton songForIndex:indexPath.row];
    SVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:SVC animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}







@end
